<template>
	<view>
		<view class='hotList' v-if="isShow && hotList.length">
			<view class='hot-bg'>
				<view class='title acea-row row-between-wrapper'>
					<view class='text line1'>
						<text class='label'>热门榜单</text>
						根据销量、搜索、好评等综合得出
					</view>
					<view class='more' hover-class="none" @click="gopage('/pages/columnGoods/HotNewGoods/index?type=2')">
						更多
						<text class="iconfont icon-jiantou"></text>
					</view>
				</view>
			</view>
			<view class='list acea-row row-middle'>
				<block v-for="(item,index) in hotList" :key='index'>
					<view class='item' @click="gopage('/pages/goods_details/index?id='+item.id)">
						<view class='pictrue'>
							<image :src='item.image'></image>
							<image v-if="index == 0" src='/static/images/one.png' class='numPic'></image>
							<image v-else-if="index == 1" src='/static/images/two.png' class='numPic'></image>
							<image v-else-if="index == 2" src='/static/images/three.png' class='numPic'></image>
						</view>
						<view class='name line1'>{{item.store_name}}</view>
						<view class='money font-color'>
							￥
							<text class='num'>{{item.price}}</text>
						</view>
					</view>
				</block>
			</view>
		</view>
		<view class='hotList' v-if="!isShow && isIframe && hotList.length">
			<view class='hot-bg'>
				<view class='title acea-row row-between-wrapper'>
					<view class='text line1'>
						<text class='label'>热门榜单</text>
						根据销量、搜索、好评等综合得出
					</view>
					<view class='more' hover-class="none" @click="gopage('/pages/columnGoods/HotNewGoods/index?type=2')">
						更多
						<text class="iconfont icon-jiantou"></text>
					</view>
				</view>
			</view>
			<view class='list acea-row row-middle'>
				<block v-for="(item,index) in hotList" :key='index'>
					<view class='item' @click="gopage('/pages/goods_details/index?id='+item.id)">
						<view class='pictrue'>
							<image :src='item.image'></image>
							<image v-if="index == 0" src='/static/images/one.png' class='numPic'></image>
							<image v-else-if="index == 1" src='/static/images/two.png' class='numPic'></image>
							<image v-else-if="index == 2" src='/static/images/three.png' class='numPic'></image>
						</view>
						<view class='name line1'>{{item.store_name}}</view>
						<view class='money font-color'>
							￥
							<text class='num'>{{item.price}}</text>
						</view>
					</view>
				</block>
			</view>
		</view>
		<view class='hotList' v-if="isIframe && !hotList.length">
			<view class='hot-bg'>
				<view class='title acea-row row-between-wrapper'>
					<view class='text line1'>
						<text class='label'>热门榜单</text>
						根据销量、搜索、好评等综合得出
					</view>
					<view class='more' hover-class="none" @click="gopage('/pages/columnGoods/HotNewGoods/index?type=2')">
						更多
						<text class="iconfont icon-jiantou"></text>
					</view>
				</view>
			</view>
			<view class='list acea-row row-middle'></view>
		</view>
	</view>
</template>

<script>
	let app = getApp()
	import {
		mapState
	} from 'vuex';
	import {
		goPage
	} from '@/libs/order.js';
	import { getHomeProducts } from '@/api/store.js';
	export default {
		name: 'goodList',
		props: {
			dataConfig: {
				type: Object,
				default: () => {}
			}
		},
		watch: {
			dataConfig: {
				immediate: true,
				handler(nVal, oVal) {
					if(nVal){
						this.isShow = nVal.isShow.val;
						this.selectType = nVal.tabConfig.tabVal;
						this.$set(this, 'selectId', nVal.selectConfig.activeValue);
						this.$set(this, 'type', nVal.selectSortConfig.activeValue);
						this.salesOrder = nVal.goodsSort.type == 1 ? 'desc' : '';
						this.newsOrder = nVal.goodsSort.type == 2 ? 'news' : '';
						this.ids = nVal.ids?nVal.ids.join(','):'';
						this.numConfig = nVal.numConfig.val;
						this.productslist();
					}
				}
			}
		},
		created() {
		},
		mounted() {},
		data() {
			return {
				hotList:[],
				name: this.$options.name,
				isShow: true,
				isIframe: app.globalData.isIframe,
				selectType:0,
				selectId: '',
				salesOrder:'',
				newsOrder:'',
				ids:'',
				page: 1,
				limit: 3,
				type: '',
				numConfig:0
			}
		},
		methods: {
			// 产品列表
			productslist: function() {
				let that = this;
				let data = {};
				if (that.selectType) {
					data = {
						page: that.page,
						limit: that.limit,
						type: that.type,
						ids: that.ids,
						selectType: that.selectType
					}
				} else {
					data = {
						page: that.page,
						limit: that.numConfig<=that.limit?that.numConfig:that.limit,
						type: that.type,
						newsOrder: that.newsOrder,
						salesOrder: that.salesOrder,
						selectId: that.selectId,
						selectType: that.selectType
					}
				}
				getHomeProducts(data).then(res => {
					that.hotList = res.data.list;
				}).catch(err => {
					that.$util.Tips({ title: err });
				});
			},
			gopage(url) {
				goPage().then(res => {
					uni.navigateTo({
						url: url
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.hotList .hot-bg {
		width: 100%;
		height: 215rpx;
		background-image: url('');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		padding: 0 30rpx;
		box-sizing: border-box;
		font-size: 24rpx;
		color: #fff;
		margin-top: 15rpx;
	}

	.hotList .hot-bg .title {
		height: 87rpx;
	}

	.hotList .hot-bg .title .text {
		width: 575rpx;
	}

	.hotList .hot-bg .title .text .label {
		font-size: 30rpx;
		font-weight: bold;
		margin-right: 20rpx;
	}

	.hotList .hot-bg .title .more {
		font-size: 26rpx;
	}

	.hotList .hot-bg .title .more .iconfont {
		font-size: 25rpx;
		vertical-align: 2rpx;
		margin-left: 10rpx;
	}

	.hotList .list {
		width: 690rpx;
		height: 330rpx;
		border-radius: 20rpx;
		background-color: #fff;
		margin: -128rpx auto 0 auto;
		padding: 0 22rpx;
		box-sizing: border-box;
		box-shadow: 0 0 30rpx -10rpx #aaa;
	}

	.hotList .list .item {
		width: 200rpx;
	}

	.hotList .list .item~.item {
		margin-left: 22rpx;
	}

	.hotList .list .item .pictrue {
		width: 100%;
		height: 200rpx;
		position: relative;
	}

	.hotList .list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.hotList .list .item .pictrue .numPic {
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
		position: absolute;
		top: 7rpx;
		left: 7rpx;
	}

	.hotList .list .item .name {
		font-size: 26rpx;
		color: #282828;
		margin-top: 12rpx;
	}

	.hotList .list .item .money {
		font-size: 20rpx;
		font-weight: bold;
		margin-top: 4rpx;
	}

	.hotList .list .item .money .num {
		font-size: 28rpx;
	}

	.empty-img {
		width: 100%;
		height: 375rpx;
		line-height: 375rpx;
		background: #ccc;
		font-size: 40rpx;
		color: #666;
		text-align: center;
	}
</style>
